import { defineConfig } from 'vite'
import react from "@vitejs/plugin-react-swc";
import path from "path";
import autoprefixer from 'autoprefixer'
import cssnano from 'cssnano'

// https://vite.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    // @路径
    // https://cn.vitejs.dev/config/#resolve-alias
    alias: {
      // 设置路径
      "~": path.resolve(__dirname, "./"),
      // 设置别名
      "@": path.resolve(__dirname, "./src"),
    },
    // https://cn.vitejs.dev/config/#resolve-extensions
    extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
  },
  css: {
    preprocessorOptions:{
      scss:{
        // 高版本使用@import 会报错 ,更好@use  需要注意私有和命名空间
        additionalData: `@use "@/styles/global.scss" as *;`,
      }
    },
    postcss: {
      plugins: [
        autoprefixer({ // 自动添加前缀
          overrideBrowserslist: [
            'Android 4.1',
            'iOS 7.1',
            'Chrome > 31',
            'ff > 31',
            'ie >= 8',
            //'last 2 versions', // 所有主流浏览器最近2个版本
          ]
        }),
        // css文件压缩
        cssnano({
          preset: 'default',
        }),
        
      ]
    },
  }
})
